package spring.module.scheduling;

import java.time.LocalTime;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * 定时任务
 *  
 * @author Lucky Yang

 */
@Slf4j
@Component
public class ScheduledTask {
    /**
     * 异步的定时任务. 任务会按计划定时运行，不管花费多长时间
     */
    @SneakyThrows
    @Async
    @Scheduled(cron = "0/1 * * * * ? ")
    public void task() {
        LocalTime start = LocalTime.now();
        int costTime = Nap.random(2000);
        log.info("异步的定时任务[{}][{}]", costTime, start);
    }
}
